package com.gastronomy.service.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gastronomy.dao.ReplayDao;
import com.gastronomy.dao.UserDao;
import com.gastronomy.entity.ReplayInformationEntity;
import com.gastronomy.entity.User;
import com.gastronomy.service.ReplayService;
@Service("replayService")
public class ReplayServiceImpl implements ReplayService{

	
	@Autowired
	private UserDao userDao;
	
	@Resource
	private ReplayDao replayDao;
	
	@Override
	public Map<String, String> addReplay(ReplayInformationEntity replayInformationEntity,User user) {

		Map<String, String> resultMap = new HashMap<String, String>();
		if(replayInformationEntity.getContent() == null || replayInformationEntity.getContent().trim().equals("")){
			resultMap.put("addResult", "FAIL");
			resultMap.put("errorMsg", "请填写回复内容");
			return resultMap;
		}
		
		User currentUser = userDao.findUserByNameAndPwd(user.getUserName(), user.getPassword());
		if(currentUser == null){
			resultMap.put("addResult", "FAIL");
			resultMap.put("errorMsg", "您没有登陆");
			return resultMap;
		}
		replayInformationEntity.setCreateTime(new Timestamp(new Date().getTime()));
		replayInformationEntity.setUser(currentUser);
		replayInformationEntity.setOrderId(1);
		try {
			replayDao.addReplay(replayInformationEntity);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			resultMap.put("addResult", "FAIL");
			resultMap.put("errorMsg", "回复失败，请稍后再试");
			return resultMap;
		}
		resultMap.put("addResult", "SUCCESS");
		return resultMap;
	}

	@Override
	public List<ReplayInformationEntity> queryReplayInformatins(
			String id, int replayType) {

		return replayDao.queryReplayInformatins(id,replayType);
	}
}
